//
//  WJMainViewController.swift
//  WJWeibo
//
//  Created by Jie on 15/12/16.
//  Copyright © 2015年 周文杰. All rights reserved.
//

import UIKit

class WJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //只读的 所以不可以这样赋值
//        tabBar = WJMainTabBar
        //用kvc来搞
        let mainTabBar = WJMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")

        //home
        let homeView = WJHomeViewController()
        addChildView(homeView, titleName: "首页", iconName: "tabbar_home")
        
        //message
        let messageView = WJMessageViewController()
        addChildView(messageView, titleName: "消息", iconName: "tabbar_message_center")

        
        //discover
        let discoverView = WJDiscoverViewController()
        addChildView(discoverView, titleName: "发现", iconName: "tabbar_discover")

        //profile
        let profileView = WJProfileViewController()
        addChildView(profileView, titleName: "我", iconName: "tabbar_profile")

    }
    
    //添加子控制器
    func addChildView(con:UIViewController, titleName: String, iconName: String){
        
        addChildViewController(UINavigationController(rootViewController: con))
        
        con.title = titleName
        
        con.tabBarItem.image = UIImage(named: iconName)
        //添加选中的图片
        let selectIcon = iconName + "_highlighted"
        //设置选中后的img并禁止系统渲染图片
        con.tabBarItem.selectedImage = UIImage(named: selectIcon)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

        //设置文字的颜色
        con.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
    }


    



}
